<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2020/01/17
 * Time: 17:54
 */

namespace HiCommon\Model;

class InsuranceCompany extends Base
{
    
    protected $table = 'insurance_company';
    
    protected $guarded = [];
    
    //public $timestamps = false;
    
    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];


    /**
     * 关联险种表
     *
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function insurance_seed(){
        return $this->hasMany(InsuranceCompanySeed::class,'insurance_company_id')->where('state',1)->select(['id','insurance_company_id','name','sort']);
    }

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getLogoAttribute($value)
    {
        $arr_data = [
          'src'=>$value,
          'full_src'=>oss_full_url($value),
        ];
        return $arr_data;
    }
        
    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
//        $arr_data               = $this->arr_state_display_name();
        $arr_data['created_at'] = ymd_friendly_date($s_created_at);
//        $arr_data['api'] = $this->table_field_api();

        return $arr_data;
    }


    /**
     * state 状态值数组
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function state_arr()
    {

        //检测状态：0无 1待检测 2检测成功 9检测失败
        $arr_check_state = [
          ['id' => -99, 'name' => '检测状态'],
          ['id' => 0, 'name' => '无'],
          ['id' => 1, 'name' => '待检测'],
          ['id' => 2, 'name' => '检测成功'],
          ['id' => 9, 'name' => '检测失败'],
        ];

        $arr_data = [
          'check_state'        => $arr_check_state,
        ];
        return $arr_data;
    }

    /**
     * 获取state值和注释的集合
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function arr_state_name()
    {
        return $this->hi_arr_state_name($this->state_arr());
    }

    /**
     * 获取state值和注释的集合
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function arr_state_display_name()
    {
        return $this->hi_arr_state_display_name($this->state_arr());
    }



    
  
}